****APPENDIX TABLE F4****

cd "$main_dir/output/tables/appendix_f"

global basic 	sex marital religion edu

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/harmonized_dataset.dta"

merge m:1 ccode survey_year yob using "$data_dir/raw/lifeexp_variables_data/growth_rate_mpd_var_exp.dta", nogen keepusing(total_growth_rate_obs yob_ln_gdppc post_fy_growth_rate fy_growth_rate pre_fy_growth_rate)

fegen subregion_yob = group(subregion yob) if yob!=-99
fegen svy_survey_year = group(survey_year survey)

cap drop sample
gen sample = 1 if born_country!=0 & total_growth_rate_obs>=0.9*(age-1) & total_growth_rate_obs!=.

//--------------------------------------------------------
//Create Table F4
//--------------------------------------------------------

//Column 1
qui reghdfe trust_govt post_fy_growth_rate fy_growth_rate pre_fy_growth_rate yob_ln_gdppc if sample==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
local list trust_govt post_fy_growth_rate fy_growth_rate pre_fy_growth_rate yob_ln_gdppc
cap drop z*
foreach x of local list {
	egen z`x' = std(`x') if e(sample)==1
}
reghdfe ztrust_govt zpost_fy_growth_rate zfy_growth_rate zpre_fy_growth_rate zyob_ln_gdppc if e(sample)==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_f4.doc, replace dec(3) nocons addtext(Geographic Unit FE, Country, ///
													    Survey Year FE x Survey FE, Yes, ///
													    Subcontinent FE x Cohort FE, Yes, ///
													    Age Sample, 25+) keep(zpost_fy_growth_rate zfy_growth_rate zpre_fy_growth_rate) 

//Column 2
qui reghdfe trust_govt post_fy_growth_rate fy_growth_rate pre_fy_growth_rate yob_ln_gdppc if sample==1 & age>=30 & age<=45, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
local list trust_govt post_fy_growth_rate fy_growth_rate pre_fy_growth_rate yob_ln_gdppc
cap drop z*
foreach x of local list {
	egen z`x' = std(`x') if e(sample)==1
}
reghdfe ztrust_govt zpost_fy_growth_rate zfy_growth_rate zpre_fy_growth_rate zyob_ln_gdppc if e(sample)==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_f4.doc, append dec(3) nocons addtext(Geographic Unit FE, Country, ///
													    Survey Year FE x Survey FE, Yes, ///
													    Subcontinent FE x Cohort FE, Yes, ///
													    Age Sample, 30-45) keep(zpost_fy_growth_rate zfy_growth_rate zpre_fy_growth_rate) 
														
//Column 3
qui reghdfe trust_govt post_fy_growth_rate fy_growth_rate pre_fy_growth_rate yob_ln_gdppc if sample==1 & age>=46 & age<=60, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
local list trust_govt post_fy_growth_rate fy_growth_rate pre_fy_growth_rate yob_ln_gdppc
cap drop z*
foreach x of local list {
	egen z`x' = std(`x') if e(sample)==1
}
reghdfe ztrust_govt zpost_fy_growth_rate zfy_growth_rate zpre_fy_growth_rate zyob_ln_gdppc if e(sample)==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_f4.doc, append dec(3) nocons addtext(Geographic Unit FE, Country, ///
													    Survey Year FE x Survey FE, Yes, ///
													    Subcontinent FE x Cohort FE, Yes, ///
													    Age Sample, 46-60) keep(zpost_fy_growth_rate zfy_growth_rate zpre_fy_growth_rate) 														
	
//Column 4
qui reghdfe trust_govt post_fy_growth_rate fy_growth_rate pre_fy_growth_rate yob_ln_gdppc if sample==1 & age>60 & age!=., absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
local list trust_govt post_fy_growth_rate fy_growth_rate pre_fy_growth_rate yob_ln_gdppc
cap drop z*
foreach x of local list {
	egen z`x' = std(`x') if e(sample)==1
}
reghdfe ztrust_govt zpost_fy_growth_rate zfy_growth_rate zpre_fy_growth_rate zyob_ln_gdppc if e(sample)==1, absorb(ccode subregion_yob svy_survey_year age $basic) cluster(ccode)
outreg2 using table_f4.doc, append dec(3) nocons addtext(Geographic Unit FE, Country, ///
													    Survey Year FE x Survey FE, Yes, ///
													    Subcontinent FE x Cohort FE, Yes, ///
													    Age Sample, 60+) keep(zpost_fy_growth_rate zfy_growth_rate zpre_fy_growth_rate) 		

														
